cmake_minimum_required(VERSION 3.16)
project(NasPlugin)

add_definitions(-DBOOST_ASIO_DISABLE_STD_ALIGNED_ALLOC)
# 定义_NAS编译宏
add_definitions(-D_NAS)
# 定义工程需要的全局变量
SET(PLUGIN_ROOT_PATH ${CMAKE_CURRENT_SOURCE_DIR}/../../..)
SET(NAS_ROOT_PATH ${CMAKE_CURRENT_SOURCE_DIR}/..)
# 插件框架的相关变量
SET(PLUGIN_FRAMEWORK_PATH ${PLUGIN_ROOT_PATH}/framework)
SET(PLUGIN_SRC_PATH ${CMAKE_CURRENT_SOURCE_DIR})
SET(PLUGIN_FRAMEWORK_LIB_PATH ${PLUGIN_FRAMEWORK_PATH}/lib)
# 定义Module模块相关的变量
SET(MODULE_ROOT_PATH ${PLUGIN_ROOT_PATH}/Module)
SET(MODULE_PLATFORM_PATH ${MODULE_ROOT_PATH}/platform)
SET(OPEN_SRC_PATH ${MODULE_ROOT_PATH}/third_open_src)
SET(OPENSRC_THRIFT_INC_PATH ${MODULE_ROOT_PATH}/third_open_src/thrift_rel/include/)
# 定义FS_Scanner模块相关的变量
SET(PLUGIN_SCANNER_PATH ${PLUGIN_ROOT_PATH}/FS_Scanner)
# 定义FS_Backup模块相关的变量
SET(PLUGIN_BACKUP_PATH ${PLUGIN_ROOT_PATH}/FS_Backup)
# 定义DME模块相关的变量
SET(DME_PATH ${PLUGIN_FRAMEWORK_PATH}/dep/dme)
SET(DME_OPENSRC_PATH ${DME_PATH}/Framework/third_party_groupware)
SET(FRAMEWORK_PLATFORM_PATH ${DME_PATH}/Framework/platform)

# 引用外部全局cmake
include(${PLUGIN_FRAMEWORK_PATH}/build/cmake/global.cmake)

# 打开编译告警
SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS}")
add_compile_options(-fPIC)

link_libraries(
    safe_cmplib
)

# 定义依赖DME相关的接口
add_library(interface_dme
    INTERFACE
    IMPORTED
    GLOBAL
)
target_include_directories(interface_dme
    INTERFACE
    ${DME_PATH}/Framework/var
    ${FRAMEWORK_PLATFORM_PATH}/SecureCLib_rel/include
    ${FRAMEWORK_PLATFORM_PATH}/FillpLib_rel/include
    ${FRAMEWORK_PLATFORM_PATH}/KMCV3_rel/include
    ${FRAMEWORK_PLATFORM_PATH}/TracePoint_rel/include
    ${FRAMEWORK_PLATFORM_PATH}/gaussdb_rel/include
    ${DME_OPENSRC_PATH}/libssh2_rel/include
    ${DME_OPENSRC_PATH}/acl_rel/include
    ${DME_OPENSRC_PATH}/libuuid_rel/include
    ${DME_OPENSRC_PATH}/libaio_rel/include
    ${DME_OPENSRC_PATH}/protobuf_rel/include
    ${DME_OPENSRC_PATH}/libiconv_rel/include
    ${DME_OPENSRC_PATH}/libxml2_rel/include
    ${DME_OPENSRC_PATH}/7z_rel/include
    ${DME_OPENSRC_PATH}/jsoncpp_rel/include
    ${DME_OPENSRC_PATH}/esdk_rel/include
    ${DME_OPENSRC_PATH}/lnfs_rel/include
    ${DME_OPENSRC_PATH}/fcgi_rel/include
    ${DME_OPENSRC_PATH}/lsmb2_rel/include
    ${DME_OPENSRC_PATH}/soci_rel/include
    ${DME_OPENSRC_PATH}/gperftools_rel/include
    ${DME_OPENSRC_PATH}/LibRdKafka_rel/include
    ${DME_OPENSRC_PATH}/lz4_rel/include
    ${DME_OPENSRC_PATH}/nghttp2_rel/include
    ${DME_OPENSRC_PATH}/pcre_rel/include
    ${DME_OPENSRC_PATH}/tinyxml2_rel/include
    ${DME_OPENSRC_PATH}/openssl_rel/include
    ${DME_OPENSRC_PATH}/leveldb_rel/include
    ${DME_OPENSRC_PATH}/curl_rel/include
    ${DME_OPENSRC_PATH}/boost_rel/include
    ${DME_PATH}/Framework/src/inc
    ${DME_PATH}/Data_Transmission_Frame/inc
    ${DME_PATH}/Framework/src/inc/system
    ${DME_OPENSRC_CARES_INCLUDE_PATH}
    ${SECODE_FUZZ_INCLUDE_PATH}
    )

target_link_directories(interface_dme
    INTERFACE
    ${FRAMEWORK_PLATFORM_PATH}/SecureCLib_rel/lib
    ${DME_OPENSRC_PATH}/jsoncpp_rel/libs
    ${DME_OPENSRC_PATH}/boost_rel/lib
    ${DME_OPENSRC_PATH}/esdk_rel/lib
    ${DME_OPENSRC_PATH}/curl_rel/lib
    ${DME_OPENSRC_PATH}/lnfs_rel/lib
    ${DME_OPENSRC_PATH}/lsmb2_rel/lib
    ${DME_OPENSRC_PATH}/leveldb_rel/out-shared
    ${DME_OPENSRC_PATH}/protobuf_rel/lib
    ${DME_OPENSRC_PATH}/sqlite_rel/unixODBC/lib
    ${DME_OPENSRC_PATH}/LibRdKafka_rel/libs
    ${DME_OPENSRC_PATH}/libssh2_rel/lib
    ${DME_OPENSRC_PATH}/openssl_rel/lib
    ${DME_OPENSRC_PATH}/soci_rel/lib64
    ${DME_OPENSRC_PATH}/libiconv_rel/lib
    ${DME_OPENSRC_PATH}/openssl_rel/lib
    ${PLUGIN_FRAMEWORK_PATH}/lib
    ${PLUGIN_FRAMEWORK_PATH}/lib/dme
    ${PLUGIN_FRAMEWORK_PATH}/lib/3rd
    ${PLUGIN_FRAMEWORK_PATH}/lib/agent_sdk
    ${PLUGIN_FRAMEWORK_PATH}/lib/dme/3rd
    ${OPEN_SRC_PATH}/libevent_rel/lib
    ${DME_OPENSRC_CARES_LIB_PATH}
    ${DME_OPENSRC_KMCV3_LIB_PATH}
    ${SECODE_FUZZ_LIB_PATH}
    )

target_link_libraries(interface_dme
    INTERFACE
    ebkcommon
    pluginsdk
    FrameCommon
    Gaussdb
    kafkaclient
    job_pool
    backup_storage_plugin
    scheduler
    securec
    json
    curl
    nfs
    smb2
    boost_chrono
    boost_atomic
    boost_thread
    boost_filesystem
    boost_system
    boost_regex
    boost_log
    boost_date_time
    eSDKOBS
    eSDKLogAPI
    log4cpp
    leveldb
    protobuf
    odbc
    rdkafka
    rdkafka++
    ssh2
    soci_core
    soci_sqlite3
    iconv
    ssl
    crypto
    event
    ${DME_OPENSRC_CARES_LIB_NAME}
    ${DME_OPENSRC_KMCV3_LIB_NAME}
    backup_layout
    safe_cmplib
    ${GCOV_LIB_NAME}
    ${SECODE_FUZZ_LIB_NAME}
)

# 定义依赖Scanner相关的依赖接口
add_library(scanner_interface
    INTERFACE
    IMPORTED
    GLOBAL
)

target_include_directories(scanner_interface
    INTERFACE
    ${PLUGIN_SCANNER_PATH}/include
    ${PLUGIN_SCANNER_PATH}/include/common
    ${PLUGIN_SCANNER_PATH}/include/filter
    ${PLUGIN_SCANNER_PATH}/include/interface
    ${PLUGIN_SCANNER_PATH}/include/model
    ${PLUGIN_SCANNER_PATH}/include/service
    ${PLUGIN_SCANNER_PATH}/include/statistics
    ${PLUGIN_SCANNER_PATH}/include/utils
    ${PLUGIN_SCANNER_PATH}/include/checkpoint
#    ${MODULE_ROOT_PATH}/src
#    ${MODULE_ROOT_PATH}/src/parser
)

target_link_directories(scanner_interface
    INTERFACE
    ${MODULE_ROOT_PATH}/
    )

target_link_libraries(scanner_interface
    INTERFACE
    )

# 定义依赖Backup相关的依赖接口
add_library(backup_interface
    INTERFACE
    IMPORTED
    GLOBAL
)

target_include_directories(backup_interface
    INTERFACE
    ${PLUGIN_BACKUP_PATH}/src/service
    ${PLUGIN_BACKUP_PATH}/src/model
#    ${MODULE_ROOT_PATH}/src
)

# 插件使用的外部依赖项，比如开源三方、插件框架、Module
add_library(interface_thrift_func
    INTERFACE
    IMPORTED
    GLOBAL
    )
target_include_directories(interface_thrift_func
    INTERFACE
    ${PLUGIN_FRAMEWORK_PATH}/inc/thrift_interface
    ${OPENSRC_THRIFT_INC_PATH}
)

add_library(interface_plugin_framework
    INTERFACE
    IMPORTED
    GLOBAL
)
target_include_directories(interface_plugin_framework
    INTERFACE
    ${PLUGIN_FRAMEWORK_PATH}/inc
)


add_library(common_dep
    INTERFACE
    IMPORTED
    GLOBAL
    )

target_include_directories(common_dep
    INTERFACE
    ${PLUGIN_ROOT_PATH}
    ${MODULE_PLATFORM_PATH}/SecureCLib_rel/include
    ${OPEN_SRC_PATH}/boost_rel/include
    ${OPEN_SRC_PATH}/openssl_rel/include
    ${OPEN_SRC_PATH}/lnfs_rel/include
    ${OPEN_SRC_PATH}/lsmb2_rel/include
    ${OPEN_SRC_PATH}/jsoncpp_rel/include

    ${MODULE_ROOT_PATH}/src
    ${MODULE_ROOT_PATH}/src/common
    ${OPENSRC_THRIFT_INC_PATH}
    ${PLUGIN_FRAMEWORK_PATH}/inc
    )

target_link_directories(common_dep
    INTERFACE
    ${MODULE_PLATFORM_PATH}/SecureCLib_rel/lib
    ${OPEN_SRC_PATH}/boost_rel/lib
    ${OPEN_SRC_PATH}/openssl_rel/lib
    ${OPEN_SRC_PATH}/jsoncpp_rel/libs
    ${OPEN_SRC_PATH}/esdk_rel/lib
    ${PLUGIN_FRAMEWORK_LIB_PATH}/thrift_interface
    )

target_link_libraries(common_dep
    INTERFACE
    safe_cmplib
    securec
    json
    ssl
    boost_chrono
    boost_atomic
    boost_thread
    boost_filesystem
    boost_system
    boost_regex
    boost_log
    boost_date_time
    eSDKOBS
    thrift_interface
    thrift_client
)


# 编译子目录
add_subdirectory(${MODULE_ROOT_PATH}/src/log log_util)
add_subdirectory(${MODULE_ROOT_PATH}/src/system system)
add_subdirectory(${MODULE_ROOT_PATH}/src/io_device io_device)
add_subdirectory(${MODULE_ROOT_PATH}/src/device_access device_access)
add_subdirectory(common)
add_subdirectory(job)
add_subdirectory(nas_service)
add_subdirectory(component)
add_subdirectory(utils)
#add_subdirectory(component)

# 生成插件动态库
add_library(nas_plugin
    SHARED
)
target_link_directories(nas_plugin
    PRIVATE
    ${PLUGIN_FRAMEWORK_PATH}/lib
    ${PLUGIN_BACKUP_PATH}/build-cmake
    ${PLUGIN_SCANNER_PATH}/build-cmake-file
    ${NAS_ROOT_PATH}/build-cmake/io_device
    ${NAS_ROOT_PATH}/build-cmake/system
    ${PLUGIN_FRAMEWORK_PATH}/lib/service
    ${MODULE_ROOT_PATH}/lib
    ${PLUGIN_SCANNER_PATH}/lib
)

target_link_libraries(nas_plugin
    PRIVATE
    application_obj
    common_dep
    # 依赖插件框架三方库
    thrift_interface
    thrift_client
    rpc
    common_util
    config_reader_util
    log_util
    system
    io_device
    device_access
    security_cbb

    #依赖的Scanner和Backup
    Scanner
    Backup

    # NAS业务的obj
    utility_obj
    job_obj
    component_obj
    nas_share_common_obj
    host_archive_restore_obj
    nas_share_backup_obj
    nas_share_restore_obj
    nas_replication_obj
    nas_livemount_obj
    nas_snapshot_obj
    nas_index_obj
    nas_resource_obj
)
